﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace SnmpForm.SysUser
{
    public partial class frmSysUserAdd : frmSysUser
    {
        public frmSysUserAdd()
        {
            InitializeComponent();
        }

        private void buttonAdd_Click(object sender, EventArgs e)
        {
            Update(false);
            DbWrapper.DbDataTypes.User user = GetUserInfo();
            if (user != null)
            {
                if (user.username.Length > 0)
                {
                    if(user.password.Length>0){
                        bool bSuccess =
                            BusinessWrapper.User.Instance.CreateUser(user);
                        if (bSuccess)
                        {
                            MessageBox.Show("创建成功");
                            Close();
                        }
                        else
                        {
                            MessageBox.Show("创建失败");
                        }
                    }
                    else{
                        labelError.Text = "密码可以为空";
                    }
                }
                else
                {
                    labelError.Text = "用户名不可以为空";
                }
            }
        }
    }
}
